
    /**
     * Created by Shijie Liu
     * 2017.6.19
     */

    /*
     * 基于js统计购物车总金额
     */
    function  getTotal() {
        var total_node = document.getElementsByClassName("subtotal");
        var i = 1;
        var price;
        var total_price = 0.00;
        for(i;i < total_node.length-1;i++){
            price = parseFloat(total_node[i].innerHTML);
            total_price += price;
        }
        // alert(total_price.toFixed(2));

        document.getElementById("price_id").innerHTML = "￥"+total_price.toFixed(2);
}

    /**
    * 统计订单总额,payc_order.php
    */

    function OrderTotal(){

        var all_node = document.getElementsByClassName("total_price_count");
        var i = 0;
        var p;
        var tp = 0.00;
        for(i;i < all_node.length;i++){
            p = parseFloat(all_node[i].innerHTML);
            tp += p;
        }

        document.getElementById("order_total").innerHTML = tp.toFixed(2);
    }

    //验证是否登陆
    function Login_Judge() {
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (xmlhttp.responseText != 0) {
                    document.getElementById("myAccount").innerHTML = xmlhttp.responseText;
                    var node = document.getElementById("user_state");
                    node.innerHTML = "退 出";
                    node.setAttribute("href", "#");
                } else {

                }
            }
        }

        xmlhttp.open("GET", "server/login_judge.php", true);
        xmlhttp.send();
    }

    window.onload = function(){Login_Judge();OrderTotal();}

    // 退出时清理cookies
    function user_quiz() {
        var xmlhttp;

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var node = document.getElementById("user_state");
                node.innerHTML = "登 录";
                node.setAttribute("href", "login.php");
                document.getElementById("myAccount").innerHTML = "用户名";
            }
        }
        xmlhttp.open("GET", "server/quit_login.php", true);
        xmlhttp.send();
    }


